package com.pig4cloud.pigx.robot.ws.collect.binance;


import com.alibaba.fastjson.JSONObject;
import com.pig4cloud.pigx.robot.ws.collect.FetchManager;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ParseData {

	public static String source_name = "binance";
	public static void parse(String msg){
		try{
			JSONObject json = JSONObject.parseObject(msg);

			switch (json.get("e").toString()){
				case "markPriceUpdate":

					//标记价格
					String k_mark = "robot_binance_markprice_" + json.getString("s").toUpperCase();
					String v_mark = json.getString("p") + "_" + json.getString("E");

					WsManager.getInstance().fetchManager.setdata(k_mark,v_mark);

					//指数价格
					String k_index = "robot_binance_indexprice_" + json.getString("s").toUpperCase();
					String v_index = json.getString("i") + "_" + json.getString("E");

					WsManager.getInstance().fetchManager.setdata(k_index,v_index);

					break;

				case "aggTrade":
					//最新价格
					String k_last = "robot_binance_lastprice_" + json.getString("s").toUpperCase();
					String v_last = json.getString("p") + "_" + json.getLong("T");

					WsManager.getInstance().fetchManager.setdata(k_last,v_last);
					break;
				default:
					break;


			}
		}catch (Exception ex){
			log.error("parse binance data error  "+ex.getMessage());
		}
	}

}
